using Tools.Domain.Specifications;
using Tools.Domain.Specifications.Common.Reflection;
using Tools.Domain.Specifications.Constraints;
using Webshop20.Domain.Orders.Specifications;

namespace Webshop20.Domain.Orders.Core
{
    public class OrderConstraintSet : ConstraintSetBase<Order>
    {
        private const decimal MINIMUM_ORDER_VALUE = 150.00m;
        
        public OrderConstraintSet(IConstraintContext concreteAssertionContext) : base(concreteAssertionContext)
        {
            ISpecification<Order> invariants = new ReferenceNotSet<Order>(x => x.Payment, "NO_PAYMENT") &
                                               new ReferenceNotSet<Order>(x => x.DeliveryAdress, "NO_DELIVERY_ADRESS") &
                                               new IntValueGreaterThan<Order>(0, x=>x.CustomerID, "NO_VALID_CUSTOMER_ID") & 
                                               //new MinimumOrderValueSpecification(MINIMUM_ORDER_VALUE) &
                                               new MinimumOrderPositionsSpecification();

            ForMethod(x => x.Execute(null, null, null)).AddPrecondition(invariants);
            AddInvariant(invariants);
        }
    }
}